Skip to content

Add GET agent code-snippets for TypeScript SDK samples - #475

Merged
bhaveshpatel640 merged 3 commits into
mainfrom
AGE-1996
Aug 27, 2026
Merged

bhaveshpatel640 merged 3 commits into
mainfrom
AGE-1996

Conversation

@bhaveshpatel640

@bhaveshpatel640 bhaveshpatel640 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a harness “Use in Code” API so the UI can fetch TypeScript SDK samples for a named agent (stream and non-stream).

AGE-1996

Changes

  • GET /api/v1/agents/{agent_id}/code-snippets
  • x-fern-ignore / x-excluded — not a public SDK method; UI should fetch this JSON (same idea as logout, not a browser redirect)
  • Returns { data: { base_url, snippets[] } } with TypeScript sample_code.stream / sample_code.non_stream
  • Samples use @truefoundry/trueforge-sdk: createTurnStream (events) vs createTurn + getTurn (no poll loop)
  • 404 when the agent id is missing
  • Patch changeset for @truefoundry/trueforge

How was this tested?

  • Unit: pnpm --filter @truefoundry/trueforge test -- tests/unit/apis/agents.test.ts (200 with a non-empty snippets array; 404 for unknown id)
  • Manual: GET http://localhost:3000/api/v1/agents/<agent_id>/code-snippets and ran the stream sample with npx tsx (needs "type": "module" in the scratch package.json)

Checklist

  • I have read the contributing guidelines
  • pnpm build, pnpm test, pnpm typecheck, pnpm lint:ci, and pnpm format:check pass locally
  • Tests added/updated where it makes sense
  • No hand-edits to generated code (packages/trueforge-sdk, .github/fern/openapi/openapi.json, docs/openapi.json) — fork PRs omit SDK regen; maintainers regenerate after merge
  • Docs / .env.example updated if configuration or behavior changed

Note

Low Risk
Read-only, UI-oriented endpoint with no changes to auth, sessions, or agent mutation; main risk is stale or misleading sample text if SDK APIs change.

Overview
Adds GET /api/v1/agents/{agent_id}/code-snippets so the harness “Use in Code” flow can load ready-to-copy TypeScript samples for a registry agent. The route is documented in OpenAPI but marked x-fern-ignore / x-excluded (UI fetch only, not a generated SDK method).

On success it returns { data: { base_url, snippets[] } }, where base_url is the request origin for SDK baseUrl and each snippet includes sample_code.stream and sample_code.non_stream. Snippets are built from templates that substitute the agent’s name and baseUrl via JSON-safe placeholder rendering (buildAgentCodeSnippets). Samples walk through @truefoundry/trueforge-sdk: create session by agent name, then either createTurnStream (with delta merging) or createTurn plus getTurn. Unknown agent_id returns 404, matching other agent routes.

Unit tests cover 404 for missing ids and a non-empty snippets array for a created agent; a patch changeset records the @truefoundry/trueforge release note.

Reviewed by Cursor Bugbot for commit 411a79c. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 411a79c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@truefoundry/trueforge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bhaveshpatel640
bhaveshpatel640 marked this pull request as ready for review August 27, 2026 14:59

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 411a79c. Configure here.

Comment thread packages/trueforge/src/schemas/agent.ts Resolved

@thesujai thesujai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bhaveshpatel640
bhaveshpatel640 merged commit a60f4c2 into main Aug 27, 2026
9 checks passed
@bhaveshpatel640
bhaveshpatel640 deleted the AGE-1996 branch August 27, 2026 15:52

@chiragjn chiragjn Aug 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: We should still add .openapi() annotations even if we are excluding them from docs and sdk - just for consistency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants